package cn.itsource.config;

import cn.itsource.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类(该配置类它主要是让自定义的拦截器生效，并且申明要拦截的接口有哪些)
 */
@Configuration //声明当前类是一个配置类
public class InterceptorMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    /**
     * 添加拦截器(让哪些拦截器生效，并且注明你要拦截哪些接口)
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //让自定义的拦截器生效
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login");  //登录放行
    }
}
